﻿namespace Water_and_electricity_metering_management_system.Models.Utils
{

    public static class HttpCode
    {
        public static int Success = 200;
        public static int Failure = 500;
        public static int Unauthorized = 401;
        public static int Forbidden = 403;
        public static int NotFound = 404;
        // 权限不足
        public static int MethodNotAllowed = 405;
        // 请求超时
        public static int RequestTimeout = 408;
    }

    public class HttpResult
    {
        public HttpResult() { }
        public HttpResult(int code, string msg, object data)
        {
            Code = code;
            Msg = msg;
            Data = data;
        }

        public int Code { get; set; } = 200;
        public string? Msg { get; set; } = "success";
        public object? Data { get; set; }

        public static HttpResult Success()
        {
            return new HttpResult(200, "success", null);
        }

        public static HttpResult Success(object data)
        {
            return new HttpResult(200, "success", data);
        }

        public static HttpResult Success(string msg, object data)
        {
            return new HttpResult(200, msg, data);
        }

        public static HttpResult Failure(object data)
        {
            return new HttpResult(500, "failure", data);
        }

        public static HttpResult Failure(string msg, object data)
        {
            return new HttpResult(500, msg, data);
        }

        public static HttpResult Failure(int code, string msg, object data)
        {
            return new HttpResult(code, msg, data);
        }
    }
}
